﻿using CommunityToolkit.Mvvm.ComponentModel;

namespace AvaloniaApplication1.ViewModels;

public sealed partial class ApplicationViewModel : ViewModelBase
{
    private bool _settingsMenuVisible;

    [ObservableProperty]
    private ApplicationPage _currentPage = ApplicationPage.Login;
    
    [ObservableProperty]
    private ViewModelBase? _currentPageViewModel;

    /// <summary>
    /// True if the side menu should be shown
    /// </summary>
    public bool SideMenuVisible { get; set; } = false;

    /// <summary>
    /// True if the settings menu should be shown
    /// </summary>
    public bool SettingsMenuVisible
    {
        get => _settingsMenuVisible;
        set
        {
            // If property has not changed...
            if (_settingsMenuVisible == value)
                // Ignore
                return;

            // Set the backing field
            _settingsMenuVisible = value;

            // If the settings menu is now visible...
            //if (value)
            //    // Reload settings
            //    Task.Run(ViewModelSettings.LoadAsync);
        }
    }

    /// <summary>
    /// Determines the currently visible side menu content
    /// </summary>
    //public SideMenuContent CurrentSideMenuContent { get; set; } = SideMenuContent.Chat;

    /// <summary>
    /// Determines if the application has network access to the fasetto server
    /// </summary>
    public bool ServerReachable { get; set; } = true;
    
    /// <summary>
    /// Navigates to the specified page
    /// </summary>
    /// <param name="page">The page to go to</param>
    /// <param name="viewModel">The view model, if any, to set explicitly to the new page</param>
    public void GoToPage(ApplicationPage page, ViewModelBase? viewModel = null)
    {
        // Always hide settings page if we are changing pages
        SettingsMenuVisible = false;

        // Set the view model
        CurrentPageViewModel = viewModel;

        // Set the current page
        CurrentPage = page;

        // Show side menu or not?
        SideMenuVisible = page == ApplicationPage.Chat;
    }
}
